<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="Keywords"
	content="云采集,云采集平台,采集,爬虫,抓取,数据采集,数据下载,数据抓取,网页爬虫,网页抓取,整站抓取,整站下载,智能抓取,智能爬虫" />
<meta name="Description"
	content="云采集,云采集平台,爬虫,抓取,采集,数据采集,数据下载,数据抓取,新一代智能云采集平台,智能大数据采集平台,新一代云采集平台." />
    <link rel="shortcut icon" href="#" type="image/png">

    <title>BDS-云采集</title>

    <link href="/web/res/css/style.css" rel="stylesheet">
    <link href="/web/res/css/style-responsive.css" rel="stylesheet">
    <link href="/web/res/js/iCheck/skins/square/square.css" rel="stylesheet">
    <link href="/web/res/css/bootstrap-switch/bootstrap-switch.min.css" rel="stylesheet">
    <style>
        .__thinkdata_highlight {
            outline: #61DA67 solid 2px;
            box-shadow: 0 0 0 4px #61DA67;
        }

        .__thinkdata_hover {
            outline: #4f7da0 solid 2px;
            box-shadow: 0 0 0 4px #4f7da0;
            background: rgba(95, 162, 214, 0.67);
        }
        th{
        	min-width: 150px;
        }
    </style>

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="/web/res/js/html5shiv.js"></script>
    <script src="/web/res/js/respond.min.js"></script>

    <![endif]-->
</head>

<body class="horizontal-menu-page">

<section>

    <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
            <!-- 
                <button type="button" class="navbar-toggle" data-toggle="collapse"
                        data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span> <span
                        class="icon-bar"></span> <span class="icon-bar"></span> <span
                        class="icon-bar"></span>
                </button>
                
              -->   
                <a class="navbar-brand" href="index.html"> <img width=150px height=50px  src="/web/res/images/logo-white.png" alt="">
                </a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse"
                 id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a href="/">返回</a></li>


                </ul>

                <ul class="nav navbar-nav navbar-right">
                    <li id="loginLi" class="dropdown">
                        <a data-toggle="modal" href="/portal/static/login.html" data-target="#myLogin"
                           class="button loginBtn special">登录/注册</a>
                    </li>

                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
    </nav>


    <!--body wrapper start-->
    <div class="wrapper">
        <div class="row">
            <div id="myPage" class="col-md-12">
                <input type="hidden" id="reqid" value="${requestId}">
                <input type="hidden" id="dname" value="${domainName}">
                <iframe frameborder="no" border="0" id="myiframe"
                        style="width: 100%;" src="${remote_url}" scrolling="yes">
                </iframe>

            </div>
        </div>

        <div class="row" style="margin-top: 10px;">
            <div class="col-md-12">
                <section class="panel">
                    <header class="panel-heading">
                        &nbsp;&nbsp;&nbsp;
                        <span class="tools pull-left"> 
                        	<button class="btn btn-primary" id="saveTpl" type="button">保存</button>
                        	<button class="btn btn-primary" id="advSet" type="button">高级配置</button>
						</span>
						 &nbsp;&nbsp;&nbsp;
						
                           
                          <input type="checkbox" id="isjs">
                          <label>启用JS </label>
                           
                       
                        &nbsp;&nbsp;&nbsp;
                         <label >模板名称</label>
                         <input type="text" id="tname" style="width:400px;height:30px;">
                       
                    </header>
                    <div class="panel-body" style="overflow-x:scroll">
                    
                     <div class="col-md-12">
                     
                      <table id="t-data" class="table table-bordered  table-hover general-table">
                           <thead>
                           <tr id="head">
                              
                              
                           </tr>
                           </thead>
                           <tbody id="cols">


                           </tbody>
                       </table>
                     
                     
                     </div>
                    
                 

                    </div>
                </section>
            </div>
        </div>
    </div>


</section>

<div class="modal fade" id="editTitleModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;
                </button>
                <h4 class="modal-title" id="">新的列名</h4>
            </div>
            <div class="modal-body">
            	<div class="row">
            	<form class="form-horizontal  col-md-12" method="post">
                    <div class="form-group">
                        <%--<label class="col-sm-2 control-label">列表路径</label>--%>
 						<input type="hidden" class="form-control" id="coluuid">
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="colName"
                                   placeholder="请输入">
                        </div>
                       
                    </div>
                </form>
            	</div>
                
                <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	                <button type="button" id="saveColName" class="btn btn-primary">确认</button>
            	</div>
            </div>

            
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>





<div class="modal fade modal-info bs-example-modal-sm" id="myLogin"
     tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-sm ">
        <div class="modal-header" style="border-bottom:0px;">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h4 class="modal-title" id="myModalLabel" style="color: #fff">登录</h4>
        </div>
        <div class="modal-content">

            <div class="modal-body">

            </div>

        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>

<div class="modal fade modal-info bs-example-modal-md" id="myRegister"
     tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-md ">
        <div class="modal-header" style="border-bottom:0px;">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h4 class="modal-title" id="myModalLabel" style="color: #fff">注册</h4>
        </div>
        <div class="modal-content">

            <div class="modal-body"
                 style="overflow-y: auto; padding-top: 0px;">

            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myEle" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;
                </button>
                <h4 class="modal-title" id="myModalLabel">编辑元素路径</h4>
            </div>
            <div class="modal-body">
            	<div class="row">
            	<form class="form-horizontal  col-md-12" method="post">
            		<div class="form-group">
                      <label class="col-sm-2 control-label">元素类型</label>
                        <div class="col-lg-10">
                                <label class="checkbox-inline">
                                    <input type="radio" name="isele"  value="list" checked>
                                    	列表
                                </label>
                                <label class="checkbox-inline">
                                    <input type="radio" name="isele"  value="element" >
                                    	单元素
                                </label>
                               
                            </div>
                        
                    </div>
                   
                     <div class="form-group">
                     
                          <label class="col-sm-2 control-label">列名</label>
						 <input type="hidden" class="form-control" id="thid" >
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="ecname"
                                   placeholder="列明"  >
                        </div>
                        
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">列表路径</label>
						<input type="hidden" id="euuid"  value="" >
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="list_path"
                                   placeholder="修改"  disabled>
                        </div>
                       
                    </div>
                    <div class="form-group">
                       
                        <label class="col-sm-2 control-label">元素路径</label>

                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="node_path"
                                   placeholder="修改" disabled >
                        </div>
                    </div>
                    <div class="form-group">
                     <label class="col-sm-2 control-label">元素属性</label>
                        <div class="col-lg-7">
                         		
                               
                              
                               <label class="checkbox-inline" class="col-sm-3 ">
                                    <input type="radio" name="attr"  value="text" checked>
                                    	文本
                                </label>
                                <label class="checkbox-inline" class="col-sm-3 ">
                                    <input type="radio" name="attr"  value="href" >
                                    	链接
                                </label>
                                 <label class="checkbox-inline" class="col-sm-3 ">
                                    <input type="radio" name="attr"  value="src" >
                                    	图片
                                </label>
                               <label class="checkbox-inline" class="col-sm-3 ">
                                <input type="radio" name="attr"  value="other" >
                                    	其他：
                               </label>
                                
                            </div>
                            <div  class="col-lg-3">
                             <input type="text" class="form-control"  id="attr"    placeholder="属性" >
                            </div>
                        
                    </div>
                     <div class="form-group">
                           <label class="control-label col-sm-2">内容</label>
                           <div class="col-sm-10" id="newTableDiv">
                               <textarea rows="6" class="form-control" id="testHtml"></textarea>
                           </div>
                       </div>
                </form>
            	</div>
                
                <div class="modal-footer">
               		<button type="button" class="btn btn-warning" id="testBtn">测试 </button>
	                <button type="button" id="saveUpColBtn" class="btn btn-primary">确认</button>
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            	</div>
            </div>

            
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>



<div class="modal fade" id="domysel" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;
                </button>
                <h4 class="modal-title" id="myModalLabel">自定义</h4>
            </div>
            <div class="modal-body">
            	<div class="row">
            	<form class="form-horizontal  col-md-12" method="post">
            	<div class="form-group">
                        <label class="col-sm-2 control-label">元素类型</label>
                        <div class="col-lg-10">
                                <label class="checkbox-inline">
                                    <input type="radio" name="myisele"  value="list" checked>
                                    	列表
                                </label>
                                <label class="checkbox-inline">
                                    <input type="radio" name="myisele"  value="element" >
                                    	单元素
                                </label>
                               
                            </div>
                        
                    </div>
                    <div class="form-group">
                     
                          <label class="col-sm-2 control-label">列名</label>
						 <input type="hidden" class="form-control" id="thid" >
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="mycname"
                                   placeholder="列明"  >
                        </div>
                        
                    </div>
                    <div class="form-group">
                     <label class="col-sm-2 control-label">元素属性</label>
                        <div class="col-lg-7">
                         		
                               
                              
                               <label class="checkbox-inline" class="col-sm-3 ">
                                    <input type="radio" name="myattr"  value="text" checked>
                                    	文本
                                </label>
                                <label class="checkbox-inline" class="col-sm-3 ">
                                    <input type="radio" name="myattr"  value="href" >
                                    	链接
                                </label>
                                 <label class="checkbox-inline" class="col-sm-3 ">
                                    <input type="radio" name="myattr"  value="src" >
                                    	图片
                                </label>
                               <label class="checkbox-inline" class="col-sm-3 ">
                                <input type="radio" name="myattr"  value="other" >
                                    	其他：
                               </label>
                                
                            </div>
                            <div  class="col-lg-3">
                             <input type="text" class="form-control"  id="myattr"    placeholder="属性" >
                            </div>
                        
                    </div>
                </form>
            	</div>
                
                <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	                <button type="button" id="saveMyColBtn" class="btn btn-primary">确认</button>
            	</div>
            </div>

            
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>





<div class="modal fade" id="myProject" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;
                </button>
                <h4 class="modal-title" >选择项目列表</h4>
            </div>
            <div class="modal-body">
            	<div class="row">
            	<form class="form-horizontal  col-md-12" method="post">
                    <div class="form-group">
                     <input type="hidden" id="celluuid"  value="" >
                       <label class="col-sm-2 control-label">项目列表</label>
                        <div class="col-sm-10">
                                  
							<select class="form-control" id="plist">
								<c:forEach var="it"  items="${sessionScope._sessionkey.plist}"   varStatus="status" begin="0" end="${sessionScope._sessionkey.plist.size()}" step="1">
			
			                         <option value="${it.id}">${it.project_name}</option>  
			
			                    </c:forEach>
							</select>
			                      
			                
			                     
                               
                            </div>
                        
                    </div>
                 
                </form>
            	</div>
                
                <div class="modal-footer">
	             
	                <button type="button" id="saveTemp" class="btn btn-warning">暂存</button>
	                <button type="button" id="saveAll" class="btn btn-primary">提交</button>
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            	</div>
            </div>

            
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>



<div class="modal fade" id="setting" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">&times;
                </button>
                <h4 class="modal-title" >高级配置</h4>
            </div>
            <div class="modal-body">
            	<div class="row">
            	<div class="col-md-12" >
                       
                        <div class="form-group col-sm-12">
                            <label for="username" class="col-sm-2">附加属性</label>

                            <div class="form-group col-sm-10">
							
								<input type="text" class="form-control" id="exts"
                                       value="" placeholder="规则：key|value,key|value 例如url|http://www.16.com,网站|网易 这样会增加2列固定属性，内容都是value的值">
                            </div>
                        </div>
                        <div class="form-group col-sm-12" >
                            <label for="username" class="col-sm-2">采集类型</label>

                            <div class="col-sm-10 icheck ">
                                <div class="square">
                                    <div class="radio ">
                                        <input jobindex="url" type="radio" checked
                                               name="job-radio"> <label>批量单页</label>
                                    </div>
                                </div>
                                <div class="square">
                                    <div class="radio ">
                                        <input jobindex="list" type="radio" name="job-radio">
                                        <label>普通翻页 </label>
                                    </div>
                                </div>
                               <div class="square">
                                    <div class="radio ">
                                        <input jobindex="click" type="radio" name="job-radio">
                                        <label>点击翻页 </label>
                                    </div>
                                </div>
								<div class="square">
                                    <div class="radio ">
                                        <input jobindex="pull" type="radio" name="job-radio">
                                        <label>下拉翻页 </label>
                                    </div>
                                </div>
                                <div class="square">
                                    <div class="radio ">
                                        <input jobindex="ajax" type="radio" name="job-radio">
                                        <label>AJAX翻页 </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="trule" class="form-group col-sm-12">
                            <label for="username" class="col-sm-2">关联链接</label>

                            <div class="form-group col-sm-10">
                                <textarea class="form-control" rows=8 id="t_urls"></textarea>
                            </div>
                        </div>
                        <div id="prule" style="display:none;" class="form-group col-sm-12">
                            <label for="username" class="col-sm-2">配置规则</label>

                            <div class="form-group col-sm-10">
                                <textarea class="form-control" rows=7 id="page_rule"  placeholder="规则：例如 https://club.autohome.com.cn/bbs/forum-c-2575-2.html 列表的翻页规则为 https://club.autohome.com.cn/bbs/forum-c-2575-[[1-10]].html ,其中[[]] 为占位符 1-10为翻页的参数，如果是一页一页翻page就写最大页码即可，如果是偏移量翻页就是按照条数翻页1-10|30 那么30为翻页码，0-30偏移量的条数"></textarea>
                            </div>
                        </div>
                        <!-- 
                        <div id="pconf" style="display:none;" class="form-group col-sm-12">
                            <label for="username" class="col-sm-2">页码配置</label>

                            <div class="form-group col-sm-8 icheck">
                            	<div class="square">
                                    <div class="radio ">
                                        <input jobindex="page" type="radio" checked
                                               name="page-radio"> <label>页码翻页</label>
                                    </div>
                                </div>
                                <div class="square">
                                    <div class="radio ">
                                        <input jobindex="offset" type="radio" name="page-radio">
                                        <label>偏移量翻页 </label>
                                    </div>
                                </div>
                              
								
                               
                            </div>
                           

                        </div>
                         -->
                        <div id="pconf" style="display:none;" class="form-group col-sm-12">
                            <label for="username" class="col-sm-2">翻页配置</label>

                            <div class="form-group col-sm-6">
                                 <select id="maxPage" class="form-control">
                                     
                                 </select>
                            </div>
                            <div class="col-sm-2 "></div>

                        </div>
                        <div  class="form-group col-sm-12">
                            <label for="username" class="col-sm-2">翻页前置条件</label>

                            <div class="form-group col-sm-10">
                                <input type="text" class="form-control"  id="preclick">
                            </div>
                        </div>
                         <div id="pclickpath" style="display:none;" class="form-group col-sm-12">
                            <label for="username" class="col-sm-2">翻页元素</label>

                            <div class="form-group col-sm-10">
                                <input type="text" class="form-control"  id="pagePath">
                            </div>
                        </div>
                       
                       


                    </div>
            	</div>
                
                <div class="modal-footer">
	             
	               
	                <button type="button" id="confOk" class="btn btn-primary">确定</button>
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            	</div>
            </div>

            
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>





<input type="hidden" id="rows" value="${rows}">
<input type="hidden" id="turl" value="${url}">
<input type="hidden" id="prid" value="${prid}">
<input type="hidden" id="columns" value="${columns}">

<!-- Placed js at the end of the document so the pages load faster -->
<script src="/web/res/js/jquery-1.10.2.min.js"></script>
<script src="/web/res/js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="/web/res/js/jquery-migrate-1.2.1.min.js"></script>
<script src="/web/res/js/bootstrap.min.js"></script>
<script src="/web/res/js/modernizr.min.js"></script>
<script src="/web/res/js/layer-v3.0.3/layer/layer.js"></script>
<script src="/web/res/js/jquery.nicescroll.js"></script>
<script src="/web/res/js/iCheck/jquery.icheck.js"></script>
<script src="/web/res/js/bootstrap-switch/bootstrap-switch.js" ></script>
<script src="/web/res/js/uuid.js"></script>
<script src="/web/res/js/md5.js"></script>
<script type="text/javascript">




    var session = "${sessionScope._sessionkey}";
    var tp = ${tp};

    if (session) {
        $("#loginLi").html("<a class='dropdown-toggle' data-toggle='dropdown' href='javascript:void(0);'>${sessionScope._sessionkey.user_name}</a><ul class='dropdown-menu'><li><a href='/action/my/m/toMyCenter'><i class='fa fa-user'></i>  个人中心</a></li> <li><a href='/action/my/m/logout'><i class='fa fa-sign-out'></i>  退出</a></li>  </ul>");
    }
    var map = new Map();
    var cur_uuid;
    var cur_cn;
    var cur_obj;

    $(document).ready(function(){
        var ifm = document.getElementById("myiframe");
        var height = document.documentElement.clientHeight;
        var ifheight = height * 0.75;
        ifm.height = ifheight;
        var op =""
        for(var i=1;i<=100;i++){
        	op+="<option value="+i+">"+i+"</option>";
        }
        $("#maxPage").append(op);
        $("#pmaxPage").append(op);
        
        $('.square input').iCheck({
            checkboxClass : 'icheckbox_square',
            radioClass : 'iradio_square',
            uncheck:true,
            increaseArea : '20%' // optional
        });
        var turl =  $('#turl').val();
        
      //  setTimeout(function(){init()},5000)
        var child_doc = $('#myiframe').prop('contentWindow').document;
        var title = jQuery(child_doc).attr("title");
    	$('#tname').val(title);	
        if(tp){
        	
         	if(tp.template_name!=null&&tp.template_name!=''&&tp.template_name!='null'&&tp.template_name!=undefined){
         		$('#tname').val(tp.template_name);	
         	}
        	
         	if(tp.isjs){
         		if(tp.isjs=='1'){
         			 $("#isjs").val("1");
         			 $("#isjs").attr("checked","checked");
         		}else{
         			$("#isjs").val("0");
         		}
         	}
         	
        	$('#exts').val(tp.exts);
        	$("#maxPage").val(tp.max_page);
        	if(tp.urls!=null||tp.urls!=''){
        		$("#t_urls").val(tp.urls);
        	}
        	$("#page_rule").val(tp.page_rule);
        	$("#pagePath").val(tp.click_path);
        	$("#preclick").val(tp.pre_click);
        	
        	var index = tp.type;
        	if (index == "url") {
        		$("input[jobindex='url']").iCheck('check');
            	$("#trule").show();
            	$("#pclickpath").hide();
            	$("#pclickconf").hide();
            	
            	$("#prule").hide();
            	$("#pconf").hide();
            }else if (index == "list") {
            	$("input[jobindex='list']").iCheck('check');
            	$("#trule").hide();
            	$("#prule").show();
            	$("#pconf").hide();
            	$("#pclickpath").hide();
            	
            }else if(index=="click"){
            	$("input[jobindex='click']").iCheck('check');
            	$("#trule").show();
            	$("#prule").hide();
            	$("#pconf").show();
            	$("#pclickpath").show();
            	
            	
            }else if(index=='pull'){
            	$("input[jobindex='pull']").iCheck('check');
            	$("#trule").show();
            	$("#prule").hide();
            	$("#pconf").show();
            	$("#pclickpath").hide();
            	
            }else if(index=='ajax'){
            	$("input[jobindex='ajax']").iCheck('check');
            	$("#trule").show();
            	$("#prule").hide();
            	$("#pconf").show();
            	$("#pclickpath").show();
            	
            }
        }
        $('#t_urls').val(turl)
        
        $('input').on('ifChecked', function(event) {

            var index = $(this).attr("jobindex");
            if (index == "url") {
            	
            	$("#trule").show();
            	$("#pclickpath").hide();
            	$("#pclickconf").hide();
            	
            	$("#prule").hide();
            	$("#pconf").hide();
            }else if (index == "list") {
            
            	$("#trule").hide();
            	$("#prule").show();
            	$("#pconf").hide();
            	$("#pclickpath").hide();
            }else if(index=="click"){
            	
            	$("#trule").show();
            	$("#prule").hide();
            	$("#pconf").show();
            	$("#pclickpath").show();
            }else if(index=='pull'){
            	
            	$("#trule").show();
            	$("#prule").hide();
            	$("#pconf").show();
            	$("#pclickpath").hide();
            	
            }else if(index=='ajax'){
            	
            	$("#trule").show();
            	$("#prule").hide();
            	$("#pconf").show();
            	$("#pclickpath").show();
            }
        });
        
        
        
        
        $("#saveTpl").click(function () {
            $.post("/action/user/u/islogin", function (data) {
                if (data.code == 200) {
                	
                	var plist = data.data.plist;
                	var op = "";
                	for(var i=0;i<plist.length;i++){
                		op+="<option value="+plist[i].id+">"+plist[i].project_name+"</option>"
                	}
                	$("#plist").html(op);
                	
                	$("#myProject").modal("show");
                
                 
                } else {
                    $("#myLogin").modal({
                        remote: "/portal/static/login.html"
                    });
                }
            });
        });
        $("#saveAll").click(function () {
        	   if (!map.isEmpty()) {
        		   var tmpl = JSON.stringify(map);
		           var requestId = $("#reqid").val();
		           var doc = $('#myiframe').prop('contentWindow').document;
		           var tname = $("#tname").val();
		           var pid = $("#plist").val();
		           var exts = $("#exts").val();
		           var type = $("input[name='job-radio']:checked").attr("jobindex");
		           var urls = $("#t_urls").val();
		           var page_rule = $("#page_rule").val();
		           var maxPage = $("#maxPage").val();
		           var pagePath = $("#pagePath").val();
		           var trLength = $("#cols tr").length;
		           
		           var preclick = $("#preclick").val();
		           
		      	   var isjs = $("#isjs").val();
		           
		           
		           var tp = {};
		           tp.tmpl=tmpl;
		           tp.template_name=tname;
		           tp.pid=pid;
		           tp.request_id=requestId;
		           tp.exts=exts;
		           tp.type=type;
		           tp.content=urls;
		           tp.page_rule=page_rule;
		           tp.isjs = isjs;
		           tp.max_page=maxPage;
		           tp.click_path=pagePath;
		           tp.rows=trLength;
		           tp.pre_click = preclick;
                   $.post("/action/tmpl/t/saveTemplate",tp, function (data) {
                       if (data.code == 200) {
                    	   $("#myProject").modal("hide");
                           window.location.href = "/action/my/m/toMyCenter/";
                       }else{
                    	   $("#myProject").modal("hide");
                       	 layer.msg(data.msg);
                       }
                   });
               } else {
                   layer.msg("请配置您要下载的数据模板")
               }
        });
        
        

		$("#saveTemp").click(function () {
			   if (!map.isEmpty()) {
		           var tmpl = JSON.stringify(map);
		           var requestId = $("#reqid").val();
		           var doc = $('#myiframe').prop('contentWindow').document;
		           var tname = $("#tname").val();
		           var pid = $("#plist").val();
		           var exts = $("#exts").val();
		           var type = $("input[name='job-radio']:checked").attr("jobindex");
		           var urls = $("#t_urls").val();
		           var page_rule = $("#page_rule").val();
		           var maxPage = $("#maxPage").val();
		           var pagePath = $("#pagePath").val();
		           var trLength = $("#cols tr").length;
		           var preclick = $("#preclick").val();
		           var isjs = $("#isjs").val();
		           var tp = {};
		           tp.tmpl=tmpl;
		           tp.template_name=tname;
		           tp.isjs = isjs;
		           tp.pid=pid;
		           tp.request_id=requestId;
		           tp.exts=exts;
		           tp.type=type;
		           tp.content=urls;
		           tp.page_rule=page_rule;
		           tp.max_page=maxPage;
		           tp.click_path=pagePath;
		           tp.rows=trLength;
		           tp.pre_click = preclick;
		           $.post("/action/tmpl/t/saveTemplate", tp, function (data) {
		               if (data.code == 200) {
		            	   $("#myProject").modal("hide");
		                   layer.msg("保存成功")
		               } else {
		            	   $("#myProject").modal("hide");
		                   layer.msg(data.msg)
		               }
		           });
		       } else {
		           layer.msg("请配置您要下载的数据模板")
		       }
		});

       
        
        $("#isjs").click(function() { 
    		 if($(this).is(':checked')){
    			$(this).val("1");
    			var furl = $("#myiframe").attr("src");
    			var index = furl.indexOf("?");
    			if(index>0){
    				furl = furl.substring(0,index);	
    			}
    			furl = furl +"?isjs=1";
    		
    			$("#myiframe").attr("src", furl); 
    		}else{
    			
    			$(this).val("0");
    			var furl = $("#myiframe").attr("src");
    			var index = furl.indexOf("?");
    			if(index>0){
    				furl = furl.substring(0,index);	
    			}
    			furl = furl +"?isjs=0";
    			
    			$("#myiframe").attr("src", furl); 
    	  }
    	});

    });
    
    $("#advSet").click(function () {
    	 $("#setting").modal("show");
    })
     $("#confOk").click(function () {
    	 $("#setting").modal("hide");
    })
    
    $("#testBtn").click(function () {
    	  var type =$("input[name='isele']:checked").val();
          var attr =$("input[name='attr']:checked").val();
    
		  var list_path = $("#list_path").val();
		  var node_path = $("#node_path").val();
		  if(attr=='other'){
	        	var v = $("#attr").val();
	        	
	        	attr = v;
	      }
		  var requestId = $("#reqid").val();
 	  	  $.get("/action/tmpl/t/testDetailPath",{"request_id":requestId,"type":type,"list_path":list_path,"node_path":node_path,"attr":attr},function(data){
 		  if(data.code==200){
 			  $("#testHtml").val(data.data)
 		  }
 		  
 	  });
 	  	  
 	  
 	  
   })
    
     function showSetting(path,ele){
   		$("input[jobindex='"+ele+"']").iCheck('check');
   	
   		$("#pagePath").val(path);
   		//$("#preclick").val(pre);
   	
       	$("#trule").show();
       	$("#prule").hide();
        $("#pconf").show();
       	$("#pclickpath").show();
    	$("#setting").modal("show");
     }
    
    
    function showPreSetting(path){
   		
   		$("#preclick").val(path);
   	
    
    	$("#setting").modal("show");
     }

    function delDataCallBack(unique_id) {
        var doc = $('#myiframe').prop('contentWindow').document;
        $("[unique_id=" + unique_id + "]", doc).removeClass('__thinkdata_highlight');//移除左键高亮
        $("[unique_id=" + unique_id + "]", doc).removeClass('__thinkdata_highlight2');//移除右键高亮
        var eles = $("[unique_id=" + unique_id + "]", doc);
        for (var i = 0; i < eles.size(); i++) {
            eles[i].removeAttribute("unique_id");
        }
        $("#row_" + unique_id).remove();//清除左侧相应列表数据
        $(".list-group-item").remove();//清除右侧列表数据
        $('#collist').append('<a href="#" class="list-group-item active"><h4 class="list-group-item-heading">列表数据</h4></a>');
        map.remove(unique_id);
    }

 
    function delCol(uuid) {
        if($("#head").children().length == 1){//删除最后一列的同时清空tbody，否则出现空行
            $('#cols').html('');
        }
        $("[uuid=" + uuid + "]").remove();
    	//var tdIndex = $(obj).parent().parent().parent().parent().index(); 
    	
        //$("#head").eq(0).find("th").eq(tdIndex).remove();
        //var ld = $("#cols  tr").length;
        //for (var i = 0; i < ld; i++) {
        //    $("#cols tr").eq(i).find("td").eq(tdIndex).remove();
        //}
        var doc = $('#myiframe').prop('contentWindow').document;
       
      
        if (($("[uuid="+uuid+"]").length == 0) ) {
            //当前属性和其链接同时删除才去除高亮
            $("[unique_id=" + uuid + "]", doc).removeClass('__thinkdata_highlight');//移除左键高亮
            $("[unique_id=" + uuid + "]", doc).removeClass('__thinkdata_highlight2');//移除右键高亮
            var eles = $("[unique_id=" + uuid + "]", doc);
            for (var i = 0; i < eles.size(); i++) {
                eles[i].removeAttribute("unique_id");
            }
        }
        deleteEmptyRow();
        map.remove(uuid);
    }
    function linkPage(uuid){
    	var col = map.get(uuid);
    	var prid = $("#reqid").val();
    	if(col.elements){
    		if(col.elements.length>0){
    			var url= col.elements[0].value;
    			var requestid = "";
    			if(col.link){
    				requestid = col.link;
    			}else{
    				requestid = Math.uuid();
        			requestid = md5(requestid);
        			col.link=requestid;
    			}
    			
    			window.open("/portal/child?child_url="+url+"&prid="+prid+"&requestid="+requestid); 
    		}else{
    			layer.msg("没有可以采集的子页面链接")
    		}
    	}else{
    		layer.msg("没有可以采集的子页面链接")
    	}
    	
    	//window.open('http://www.jb51.net'); 
    }
    
    function saveCell(){
    	var uuid = $("#celluuid").val();
    	
    	var type =$("input[name='cellType']:checked").val();
    	
    	var index = 0; 
        var repval = "";
        var varval = "";
    	var trs =  $("#cols tr"); 
    	
    	var max = trs.length;
    	for(var j=0;j<trs.length;j++){
    		var tr = trs[j];
            var items =  $(tr).find("td");
            for(var i=0;i<items.length;i++){
            	var tditem = items[i];
            	if ($(tditem).attr("uuid")==uuid) {
            		varval = $(tditem).text();
            		$(tditem).text(repval);
            		repval = varval;
            	
                }
            }
    	}
    	
    	if(map.get(uuid).op==null||map.get(uuid).op==""||map.get(uuid).op==undefined){
    		var op = {};
    		op.addCell=1;
    		op.cellType=type;
        	map.get(uuid).op = op;
    	}else{
    		var v = map.get(uuid).op["addCell"];
    		v = (v +1);
    		map.get(uuid).op["addCell"]=v;
    		map.get(uuid).op["cellType"]=type;
    	}
    	$('#myCell').modal('hide');
    	$("#celluuid").val("");
    }
    
    function addCell(uuid){
    	$('#myCell').modal('show');
        $("#celluuid").val(uuid);	
    }

    function editCol(unique_id,list_path,node_path,request_id,column_name,column_type) {
    	if(list_path!=null&&list_path!=''&&list_path!=undefined&&list_path!='null'){
            $('#list_path').removeAttr('disabled');
            $('#list_path').val(list_path);
        }else{
        	$('#list_path').val("");
            $('#list_path').attr('disabled','true');
        }
        if(node_path!=null&&node_path!=''&&node_path!=undefined&&node_path!='null'){
            $('#node_path').removeAttr('disabled');
            $('#node_path').val(node_path);
        }else{
        	$('#node_path').val("")
            $('#node_path').attr('disabled','true');
        }
        
        
      
        if(column_type=='list'){
        	
        	$("input[name='isele']:eq(0)").attr("checked",'checked'); 
        }else{
        	$("input[name='isele']:eq(1)").attr("checked",'checked'); 
        }
        $("#testHtml").val("")
        $('#euuid').val(unique_id);
        $('#ecname').val(column_name);
        $('#myEle').modal('show');

    
       
    }
    function editTitle(uuid) {
        //console.log($(obj).text())
        var a = $("th[uuid='"+uuid+"']").find("a");
        
        var name =  $(a[0]).text();
        $('#colName').val(name)
        $('#editTitleModal').modal('show');
        $("#coluuid").val(uuid)
        //cur_obj = obj;
    }
    $("#saveUpColBtn").click(function () {
        var domainName = $("#dname").val();
        if (domainName.indexOf('http') < 0) {
            domainName = 'http://' + domainName;
        }
        var type =$("input[name='isele']:checked").val();
        var attr =$("input[name='attr']:checked").val();
        if(attr=='other'){
        	var v = $("#attr").val();
        	if(v==null||v==''||v==undefined){
        		layer.msg("请填写您要采集的元素属性");
        		return;
        	}
        	attr = v;
        }
        
     
     
        var unique_id=  $('#euuid').val();
        var requestId = $("#reqid").val();
        var column_name =  $('#ecname').val();
        document.getElementById('myiframe').contentWindow.parseElePath(domainName,$("#list_path").val(),$("#node_path").val(),unique_id,requestId,column_name,type,attr);
        $('#myEle').modal('hide');
    });
    $('#saveColName').click(function(){
        var newColName = $('#colName').val().trim();
        if(newColName == ''){
            layer.msg('列名不能为空')
            return;
        }
        var uuid = $("#coluuid").val();
      
        $("[uuid="+uuid+"]").children('a').text(newColName);
     
        map.get(uuid).column_name = newColName;
        $('#editTitleModal').modal('hide');
    });
    
    $('#saveMyColBtn').click(function(){
    	 var domainName = $("#dname").val();
         if (domainName.indexOf('http') < 0) {
             domainName = 'http://' + domainName;
         }
        var newColName = $('#mycname').val().trim();
        if(newColName == ''){
            layer.msg('列名不能为空')
            return;
        }
        var type =$("input[name='myisele']:checked").val();
        var attr =$("input[name='myattr']:checked").val();
        if(attr=='other'){
        	var v = $("#myattr").val();
        	if(v==null||v==''||v==undefined){
        		layer.msg("请填写您要采集的元素属性");
        		return;
        	}
        	attr = v;
        }
        var requestId = $("#reqid").val();
        var tid = $("#thid").val();
        
        document.getElementById('myiframe').contentWindow.addTemplateDetail(domainName, requestId, newColName, type, tid,attr);
        $('#domysel').modal('hide');
    });
    

    function showDoMySel(thid,cname){
    	$("#mycname").val(cname);
    	$("#thid").val(thid);
    	$("#myattr").val("")
    	$('#domysel').modal('show');
    }
    
    function deleteEmptyRow() {
        var isEmpty = true;
        $("#cols tr").each(function (index, item) {
            $(item).find("td").each(function (tdindex, tditem) {
                if ($(tditem).text()) {
                    isEmpty = false;
                }
            });
            if (isEmpty) {
                $(item).remove();
            }
            isEmpty = true;
        });
    }

    function editColNameCallBack(unique_id) {
        $("#editBtn_"+unique_id).css("display","block");
        $("#editBtn_"+unique_id).click(function(){
            //修改列名
            var newColumnName = $("#columnName_"+unique_id).val() || '';
            if (newColumnName != '') {
                map.get(unique_id).column_name = newColumnName;
            }
            $("#editBtn_"+unique_id).css("display","none");
        });
    }

    function hideBtnCallBack(unique_id,column_name) {
        setTimeout("$('#editBtn_"+unique_id+"').css('display','none');",150);//避免与确定按钮冲突
        //setTimeout("$('#editBtn_"+unique_id+"').css('display','none');$('#columnName_"+unique_id+"').val('"+column_name+"');",150);//避免与确定按钮冲突
    }

    function addMap(uuid, data) {

        map.put(uuid, data);

    }

    function Map() {
        var struct = function (key, value) {
            this.key = key;
            this.value = value;
        }

        var put = function (key, value) {
            for (var i = 0; i < this.arr.length; i++) {
                if (this.arr[i].key === key) {
                    this.arr[i].value = value;
                    return;
                }
            }
            this.arr[this.arr.length] = new struct(key, value);
        }

        var get = function (key) {
            for (var i = 0; i < this.arr.length; i++) {
                if (this.arr[i].key === key) {
                    return this.arr[i].value;
                }
            }
            return null;
        }

        var remove = function (key) {
            var v;
            for (var i = 0; i < this.arr.length; i++) {
                v = this.arr.pop();
                if (v.key === key) {
                    continue;
                }
                this.arr.unshift(v);
            }
        }

        var size = function () {
            return this.arr.length;
        }

        var isEmpty = function () {
            return this.arr.length <= 0;
        }
        this.arr = new Array();
        this.get = get;
        this.put = put;
        this.remove = remove;
        this.size = size;
        this.isEmpty = isEmpty;
    }
</script>
<%--<script src="/web/res/js/fetch-element.js"></script>--%>

<!--common scripts for all pages-->
<script src="/web/res/js/scripts.js"></script>

</body>
</html>

